package Com.javaserver.dao;

import Com.javaserver.bean.admid;
import Com.javaserver.utils.DB;


import java.util.List;
import java.util.Map;


public class admidserver {





    //登录类
    public boolean login(String act,String paw) {
        if ("".equals(paw) || "".equals(act)) {
            return false;
        }
        //具体的功能操作代码
        //1.根据acc取数据库数据
        //2.如果取不出数据则说明用户不存在
        //3.如果取出的数据，密码跟传入的密码不相同，说明密码错误
        List<Map<String, Object>> result = DB.executeQuery("select * from admin where account = ?",act);
        String database = null;
        //从数据库获取password这个字段
        if (result != null) {
            for (int i = 0; i < result.size(); i++) {
                database = (String) result.get(i).get("password");
            }
        }
        //获取该字段判断
        if (paw.equals(database)) {
            return true;
        }
        return false;
    }




    //注册类
        public admid register(admid user) {
        int k = DB.executeUpdate("insert into admin (account,password) values( ?, ?)",user.getAccount(),user.getPassword());
            if (k == -1){
                return null;
            }
                return user;
        }



    }


